home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / machack / Hacks96 / FlyPaper.sit / Fly Paper / FlyPaper Source / App Sources / FlyPaperUtils.cpp < prev    next >
C/C++ Source or Header  |  1996-06-22  |  3KB  |  133 lines

  1. #include "ST_MacClasses.h"
  2. #ifndef FLYPAPERUTILS_H
  3. #include "FlyPaperUtils.h"
  4. #endif
  5.  
  6. #ifndef FLYPAPERAPP_H
  7. #include "FlyPaperApp.h"
  8. #endif
  9.  
  10. #include <folders.h>
  11.  
  12. Handle    TempGet1Resource (ResType type, short id)
  13. {
  14.     Handle        resHandle;
  15.     
  16.     SetResLoad (false);
  17.     resHandle = Get1Resource (type, id);
  18.     SetResLoad (true);
  19.     if (!resHandle)
  20.         return nil;
  21.     
  22.     ST_ResourceHandle    resHandleKiller (resHandle);
  23.     
  24.     long        size = SizeResource (resHandle);
  25.     if (size < 0)
  26.         return nil;
  27.     
  28.     OSErr        error;
  29.     Handle        tempHandle = TempNewHandle (size, &error);
  30.     if (!tempHandle)
  31.         return nil;
  32.     
  33.     ST_Handle    tempHandleKiller (tempHandle);
  34.     HLock (tempHandle);
  35.     ReadPartialResource (resHandle, 0, *tempHandle, size);
  36.     HUnlock (tempHandle);
  37.     
  38.     if (ResError () == noErr) {
  39.         tempHandleKiller.Forget ();
  40.         return tempHandle;
  41.     } else
  42.         return nil;
  43. }
  44.  
  45. Boolean    OptionKeyDown (void)
  46. {
  47.     KeyMap        map;
  48.     
  49.     GetKeys (map);
  50.     return (map [1] & 0x00000004) ? true : false;
  51. }
  52.  
  53. OSErr FlyPaperFindFolder (short vRefNum, OSType folderType, Boolean createFolder,
  54.                     short *foundVRefNum, long *foundDirID)
  55.                     
  56. {
  57.     OSErr                error;
  58.  
  59.     switch (folderType) {
  60.     
  61.         case (kFlyPaperAppFolder) : {
  62.             
  63.             FCBPBRec        fcbPB;
  64.  
  65.             fcbPB.ioNamePtr = nil;
  66.             fcbPB.ioVRefNum = 0;
  67.             fcbPB.ioRefNum = gResFile;
  68.             fcbPB.ioFCBIndx = 0;
  69.             
  70.             error = PBGetFCBInfoSync (&fcbPB);
  71.             
  72.             *foundDirID = fcbPB.ioFCBParID;
  73.             *foundVRefNum = fcbPB.ioFCBVRefNum;
  74.             
  75.             break;
  76.         }
  77.                 
  78.         case (kClippingsFolder) : {
  79.         
  80.             CInfoPBRec    pb;
  81.                     
  82.             error = FlyPaperFindFolder (vRefNum, kSystemFolderType, false, foundVRefNum, foundDirID);
  83.                         
  84.             if (!error) {
  85.                 pb.hFileInfo.ioNamePtr = gClippingsFolderName;
  86.                 pb.hFileInfo.ioVRefNum = *foundVRefNum;
  87.                 pb.hFileInfo.ioDirID = *foundDirID;
  88.                 pb.hFileInfo.ioFDirIndex = 0;                
  89.                 error = PBGetCatInfoSync (&pb);
  90.                 *foundDirID = pb.hFileInfo.ioDirID;
  91.                 
  92.                 if (error == fnfErr && createFolder)
  93.                     error = DirCreate (*foundVRefNum, *foundDirID, gClippingsFolderName, foundDirID);
  94.             }
  95.         
  96.             break;
  97.         }
  98.         
  99.         default:
  100.         
  101.             // To allow passing of 0 as system disk.
  102.         
  103.             if (vRefNum == 0)
  104.                 vRefNum = kOnSystemDisk;
  105.                 
  106.             error = FindFolder (vRefNum, folderType, createFolder, foundVRefNum, foundDirID);
  107.     }
  108.             
  109.     return (error);
  110. }
  111.  
  112. void ClassifyPoint (Point p, Boolean* onLeft, short* offset)
  113. {
  114.     Rect            bigRect = (**GetGrayRgn ()).rgnBBox;
  115.     if (bigRect.right - p.h > p.h - bigRect.left)
  116.         *onLeft = true;
  117.     else
  118.         *onLeft = false;
  119.     
  120.     // cycle through devices and find offset from top of device to p.v
  121.     
  122.     GDHandle        dev = GetDeviceList ();
  123.     while (dev) {
  124.         Rect        r = (**dev).gdRect;
  125.         if (PtInRect (p, &r)) {
  126.             *offset = p.v - r.top;
  127.             return;
  128.         }
  129.         dev = GetNextDevice (dev);
  130.     }
  131.     *offset = 0;
  132. }
  133.